/**
 * OMS业务员弹框
 */
import React from 'react';
import PopupSelection from '../../el/ItemComponent/PopupSelection';
import requests from '@/utils/request';
import ElNotification from '@/components/el/ElNotification';

interface Props {
  params?: object;
}
class SalesmanPoPupSelection extends React.Component<Props> {
  constructor(props) {
    super(props);
  }
  onRef: any; //组件的ref

  /**
   * 分页请求
   * @param formData
   * @returns
   */
  request = async (formData) => {
    const params = {
      ...formData,
      ...this.props?.params,
      orders: [{ asc: false, column: 'createTime' }]
    };
    const res = await requests('/yst-support/org/component/emp/paging', {
      method: 'post',
      query: { ...params }
    });
    if (res && res.success) {
      //因为更改接口，导致字段名与原接口不一致，在此之前页面的联动逻辑已经写好，所以转换下数据
      res.data?.records?.forEach((x) => {
        x.agentEmpId = x.id;
        x.agentName = x.empName;
        x.agentCode = x.empCode;
      });
    }
    return res;
  };

  render() {
    return (
      <PopupSelection
        rowKey='agentEmpId'
        modalTitle='请选择业务员'
        tableProxy={{
          request: this.request,
          errCallBack: (res) => {
            ElNotification({
              type: 'error',
              message: res.msg || '操作失败'
            });
          },
          props: {
            success: 'success',
            result: 'data.records',
            total: 'data.total'
          },
          autoLoad: true
        }}
        modalTableColumns={[
          {
            title: '业务员编码',
            width: 100,
            dataIndex: 'empCode',
            align: 'center'
            // render: (...[, record]) => {
            //   return <span>{record?.invWhRespVO?.agentEmpId}</span>;
            // }
          },
          {
            title: '业务员名称',
            width: 100,
            dataIndex: 'empName',
            align: 'center'
            // render: (...[, record]) => {
            //   return <span>{record?.invWhRespVO?.empName}</span>;
            // }
          },
          {
            title: '业务员公司',
            width: 100,
            dataIndex: 'ouName',
            align: 'center'
          }
        ]}
        columns={[
          {
            title: '业务员编码',
            width: 100,
            dataIndex: 'agentEmpId',
            align: 'center'
            // render: (...[, record]) => {
            //   return <span>{record?.invWhRespVO?.whCode}</span>;
            // }
          },
          {
            title: '业务员名称',
            width: 100,
            dataIndex: 'empName',
            align: 'center'
            // render: (...[, record]) => {
            //   return <span>{record?.invWhRespVO?.whName}</span>;
            // }
          },
          {
            title: '业务员公司',
            width: 100,
            dataIndex: 'ouName',
            align: 'center'
          }
        ]}
        searchFormProps={{
          items: [
            {
              title: '输入搜索',
              name: 'empCodeName',
              span: 6,
              formOption: {
                type: '$input',
                props: { placeholder: '业务员编码/业务员名称' }
              }
            }
          ]
        }}
        needModal={true}
        onRef={this.onRef}
        keywords='empCodeName'
        // value={this.props.value}
        // onChange={this.props.onChange}
        overLayWidth={600}
        {...this.props}
      />
    );
  }
}

export default SalesmanPoPupSelection;
